import React, { Component, Fragment } from 'react';
import {Form, Input,  Button,message } from 'antd';
import { connect } from 'dva';
import { createModalContainer } from '@/components/changeModal';
import styles from './index.less';

const FormItem = Form.Item;
const { TextArea } = Input;
@Form.create()
class ReplyModal extends React.Component {
    constructor(props) {
        super(props);

    }

    componentDidMount() {
        window.Isoption = true;
        const {
            getFieldDecorator, getFieldsError, getFieldError, isFieldTouched, getFieldsValue
        } = this.props.form;
    }
    componentWillMount() {
        window.Isoption = false;
      }
    // 取消
    handleCancel = () => {
        this.props.cancel();
    }
    handleSubmit = () => {
        const { dispatch } = this.props;
        this.props.form.validateFields((err, values) => {

            dispatch({
                type: `orderRates/Reply`,
                params: values,
                callBack: {
                    success: (data) => {
                        message.success("回复成功")
                        this.handleCancel()
                    }, error: (data) => {
                        console.log(data)
                        message.error("回复失败")
                    }
                }
            });
        })
    }
    render() {
        const { loadReply } = this.props;
        const {
            getFieldDecorator, getFieldsError, getFieldError, isFieldTouched, getFieldsValue
        } = this.props.form;
        const formItemLayout = {
            labelCol: {
                xs: { span: 6 },
                sm: { span: 6 },
            },
            wrapperCol: {
                xs: { span: 16 },
                sm: { span: 16 },
            },
        };
        return (

            <Form>
                <Form.Item
                    {...formItemLayout}
                    label=""
                >
                    {getFieldDecorator('Id', {
                        initialValue: this.props.param.Id,
                    })(
                        <input type="hidden" />
                    )}
                </Form.Item>
                <Form.Item
                    {...formItemLayout}
                    label="回复内容："
                >
                    {getFieldDecorator('Content', {
                        rules: [{ required: true, message: '请输入回复内容' }]
                    })(
                        <TextArea rows={4} maxLength={50} />
                    )}
                </Form.Item>
                <FormItem className="xkd-model-footBtn">
                    <Button onClick={this.handleCancel} className="xkd-mr16">
                        取消
                    </Button>
                    <Button
                        type="primary"
                        onClick={this.handleSubmit}
                        loading={loadReply}

                    >
                        确定
                    </Button>
                </FormItem>
            </Form>


        )
    }
}
const Reply = createModalContainer(
    connect(({ orderRates, global, loading }) => ({
        evaluateList: orderRates.evaluateList,
        oemInfo: global.oemInfo,
        loadReply: loading.effects['orderRates/Reply'],
    }))(ReplyModal),
    true,
    true
);
export default Reply;
